﻿Imports System.Data.OleDb
Public Class TagGame
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Submit.Click
        Dim sql As String = "INSERT INTO GameTag (Game_fkID,Tag_fkID) VALUES (@f1,@f2)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("WarriorConnection").ConnectionString)
        conn.Open()
        For Each cb As ListItem In cb_Tags.Items
            If cb.Selected = True Then
                Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
                cmd.Parameters.AddWithValue("@f1", Request.QueryString("ID"))
                cmd.Parameters.AddWithValue("@f2", cb.Value)
                cmd.ExecuteNonQuery()
            End If
        Next
        conn.Close()
        Response.Redirect("GameByTag.aspx")
    End Sub

    Protected Sub btn_AddTag_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_AddTag.Click
        Dim sql As String = "INSERT INTO Tag (TagName) VALUES (@f1)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("WarriorConnection").ConnectionString)
        conn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", tb_TagName.Text)
        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("TagGame.aspx?ID=" & Request.Params("ID"))
    End Sub
End Class